﻿
@{
    Layout = null;
}
@model PackDTO
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>添加包装类型</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" type="text/css" href="~/common/layui/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="~/common/bootstrap/css/bootstrap.css" media="all">
    <link rel="stylesheet" type="text/css" href="~/common/global.css" media="all">
    <link rel="stylesheet" type="text/css" href="~/css/personal.css" media="all">
</head>
<body class="childrenBody">
    <form class="layui-form ">
        <div class="layui-form-item col-lg-5">
            <label class="layui-form-label">包装类别名称:</label>
            <div class="layui-input-block">
                <input name="id" value="@Model.Id" type="hidden">
                <input class="layui-input newsAuthor" value="@Model.Name" name="name" lay-verify="required" placeholder="如:盒装" type="text">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">价格：</label>
            <div class="layui-input-inline">
                <input type="text" name="price" lay-verify="required|price" value="@Model.Price" placeholder="请输入价格" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="edit">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
    <script type="text/javascript" src="~/common/laydate.js"></script>
    <script type="text/javascript" src="~/common/layui/layui.all.js"></script>
    <script type="text/javascript">

        //执行一个laydate实例
        laydate.render({
            elem: '#datetime' //指定元素
        });

        layui.config({
            base: "js/"
        }).use(['form', 'layer', 'jquery', 'layedit'], function () {
            var form = layui.form,
                layer = parent.layer === undefined ? layui.layer : parent.layer,
                laypage = layui.laypage,
                layedit = layui.layedit,
                $ = layui.jquery;

            //数据验证
            form.verify({
                price: function (value, item) {
                    if (isNaN(value)) {
                        return '请输入正确的价格';
                    }
                },
                pass: [
                    /^[\S]{6,12}$/
                    , '密码必须6到12位，且不能出现空格'
                ]
            });


            //此处的edit是39行代码中提交按钮的 lay-filter属性
            form.on("submit(edit)", function (data) {

                var index = top.layer.msg('数据修改中，请稍候', { icon: 16, time: false, shade: 0.8 });

                var formData = $(".layui-form").serialize();    //表单数据

                $.ajax({
                    url: "/Pack/Edit",
                    method: "POST",
                    dataType: "json",
                    data: formData,
                    traditional: true,//这里设置为true
                    success: function (res) {
                        top.layer.close(index);
                        if (res.status == "ok") {
                            layer.msg("修改成功", {
                                icon: 1, time: 2000, end: function () {
                                    
                                    layer.closeAll("iframe");
                                    //刷新父页面
                                    parent.location.reload();
                                }
                            });



                        } else {
                            top.layer.close(index);
                            layer.msg("修改失败:" + res.errorMsg, {
                                icon: 5, time: 2000, end: function () {
                                   
                                    layer.closeAll("iframe");
                                    //刷新父页面
                                    parent.location.reload();
                                }
                            });
                        }
                    },
                    error: function () {
                        top.layer.close(index);
                        layer.msg("网络请求失败", {
                            icon: 5, time: 2000, end: function () {
                                
                                layer.closeAll("iframe");
                                //刷新父页面
                                parent.location.reload();
                            }
                        });
                    }
                });

                return false;
            })

        })

    </script>
</body>
</html>